<?php

/**
 * ucenik actions.
 *
 * @package    dnevnik
 * @subpackage ucenik
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 12479 2008-10-31 10:54:40Z fabien $
 */
class ucenikActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request)
  {

  }

  public function executeGrid(sfWebRequest $request)
  {
      $grid = new Grid($request, 'ucenik');
      //$grid->render();
      return $this->renderText($grid->render());
  }

  public function executeDnevnik(sfWebRequest $request)
  {
      $ucenik = DbFinder::from('Ucenik')->findPk($request->getParameter('ucenik_id'));
      $dnevnik = new Dnevnik($ucenik);
      $this->ucenik = $ucenik;
      list($this->predmets, $this->izbornis) = $dnevnik->getPredmetiUcenika();
      $this->ocenas = $dnevnik->getUcenikOcenas();
      $this->smer = $ucenik->getRazred()->getSmer();

      $this->getResponse()->addJavascript('jquery.js');
      $this->getResponse()->addJavascript('jquery.boxy.js');
      $this->getResponse()->addJavascript('dnevnik_administracija.js');
      $this->getResponse()->addStylesheet('boxy.css');
      return $dnevnik->getTemplate();
  }

  public function executeUploadImage(sfWebRequest $request)
  {
     $uc_arr = explode('_', $request->getParameter('id'));
     $ucenik_id = $uc_arr[1];
     $newname = $ucenik_id;

     $uploaddir = sfConfig::get('sf_web_dir').'/images/profil/';
     $uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

     if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile))
     {
     }
     else die('Greska!!');

     $img = new sfImage($uploadfile, 'image/jpg');
     $img->resize(85, 113);
     $img->saveAs($uploaddir.$newname.'.jpg');
     unlink($uploadfile);

     return ($this->renderText("<img src='/images/profil/".$newname.".jpg' />"));
  }

  public function executeUnesiOcenu(sfWebRequest $request)
  {
     return $this->renderText(Dnevnik::unesiOcenu($request));
  }

  public function executePromeniOcenu(sfWebRequest $request)
  {
     return $this->renderText(Dnevnik::promeniOcenu($request));
  }

  public function executeUnesiOpisnuOcenu(sfWebRequest $request)
  {
     return $this->renderText(Dnevnik::unesiOpisnuOcenu($request));
  }

  public function executePromeniOpisnuOcenu(sfWebRequest $request)
  {
     return $this->renderText(Dnevnik::promeniOpisnuOcenu($request));
  }

  public function executePromeniZakljucnu(sfWebRequest $request)
  {
     return $this->renderText(Dnevnik::promeniZakljucnu($request));
  }

  public function executePromeniOpisnuZakljucnu(sfWebRequest $request)
  {
     return $this->renderText(Dnevnik::promeniOpisnuZakljucnu($request));
  }

}